package com.itheima.mall.controller;

import com.itheima.mall.pojo.HomeRecommendSubject;
import com.itheima.mall.service.SmsHomeRecommendSubjectService;
import com.itheima.mall.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/recommendSubject")
public class SmsHomeRecommendSubjectController {

    @Autowired
    private SmsHomeRecommendSubjectService smsHomeRecommendSubjectService;


    /**
     * 添加首页推荐专题
     */
    @PostMapping("/create")
    public ResponseEntity<String> createSubject(@RequestBody List<HomeRecommendSubject> homeRecommendSubjectList){
        smsHomeRecommendSubjectService.createSubject(homeRecommendSubjectList);
        return ResponseEntity.ok("ok");
    }

    /**
     * 批量删除推荐
     */
    @PostMapping("/delete")
    public ResponseEntity<String> deleteSubject(@RequestParam List<Long> ids){
        smsHomeRecommendSubjectService.deleteSubject(ids);
        return ResponseEntity.ok("ok");
    }

    /**
     * 分页查询推荐
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult> listSubject(Integer pageNum,Integer pageSize,Integer recommendStatus,String subjectName){
        PageResult pageResult = smsHomeRecommendSubjectService.listSubject(pageNum,pageSize,recommendStatus,subjectName);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 批量修改推荐状态
     */
    @PostMapping("/update/recommendStatus")
    public ResponseEntity<String> updateStatus(@RequestParam List<Long> ids,Integer recommendStatus){
        smsHomeRecommendSubjectService.updateStatus(ids,recommendStatus);
        return ResponseEntity.ok("ok");
    }

    /**
     * 修改推荐排序
     */
    @PostMapping("/update/sort/{id}")
    public ResponseEntity<String> updateSort(@PathVariable Long id,Integer sort){
        smsHomeRecommendSubjectService.updateSort(id,sort);
        return ResponseEntity.ok("ok");
    }

}
